Test the background caching mechanism

Load software and data


In [1]:
%run ../../load_fretbursts.py


C:\Data\Antonio\software\src\fretbursts
 - Optimized (cython) burst search loaded.
 - Optimized (cython) photon counting loaded.

FRETBursts revision:
 2014-08-04 9c0d8b2 Fix bg_cache (broken since ph_sel refactor)

Load and process the data:


In [2]:
data_dir = 'C:\Data\Antonio\data/'

In [3]:
fname = data_dir + u'/manta/2014-04-11/17d_200p_2_600mW_reall_steer_20.dat'

In [4]:
d1 = loader.multispot48(fname)
d2 = loader.multispot48(fname)


 - Loading HDF5 file: C:\Data\Antonio\data//manta/2014-04-11/17d_200p_2_600mW_reall_steer_20.hdf5 ... DONE.
 - Loading HDF5 file: C:\Data\Antonio\data//manta/2014-04-11/17d_200p_2_600mW_reall_steer_20.hdf5 ... DONE.

In [5]:
def compare_data_bg(d1, d2):
    mch_arrays = ['bg', 'bg_dd', 'bg_ad', 'bg_aa', 'Lim', 'Ph_p']
    scalars = ['nperiods', 'bg_time_s', 'bg_auto_th', 'bg_fun_name']
    for name in mch_arrays:
        for ich, arr in enumerate(d1[name]):
            assert np.allclose(arr, d2[name][ich])
    for name in scalars:
        assert d1[name] == d2[name]

In [6]:
#reload(bg_cache)

Manual threshold


In [7]:
bg_cache.remove_cache(d2)


 * Removing all the cached background data ... [DONE]

In [8]:
d1.calc_bg(bg.exp_fit, time_s=20, tail_min_us=300)
d2.calc_bg_cache(bg.exp_fit, time_s=20, tail_min_us=300)


 - Calculating BG rates ... [DONE]
 * No cached BG rates, recomputing:
 - Calculating BG rates ... [DONE]
 * Storing BG  to disk ... 
 - Saving arrays/scalars: bg, bg_time_s, Ph_p, Lim, nperiods, bg_dd, bg_auto_th, bg_da, bg_th_us_user, bg_aa, bg_ad, 
 - Saving HDF5 attributes: bg_fun, bg_fun_name, 
 [DONE]

In [9]:
compare_data_bg(d1, d2)

In [10]:
d2.calc_bg_cache(bg.exp_fit, time_s=20, tail_min_us=300)


 * Loading BG rates from cache ... 
 - Loading arrays/scalars: Lim, Ph_p, bg, bg_aa, bg_ad, bg_auto_th, bg_da, bg_dd, bg_th_us_user, bg_time_s, nperiods, 
 - Loading HDF5 attributes: bg_fun, bg_fun_name, signature, 
 - Generating additional fields: bg, bg_dd, bg_ad, bg_da, bg_aa, 
 [DONE]

In [11]:
compare_data_bg(d1, d2)

Auto threshold


In [12]:
d1.calc_bg(bg.exp_fit, time_s=20, tail_min_us='auto', F_bg=1.7)
d2.calc_bg_cache(bg.exp_fit, time_s=20, tail_min_us='auto', F_bg=1.7)


 - Calculating BG rates ... [DONE]
 * No cached BG rates, recomputing:
 - Calculating BG rates ... [DONE]
 * Storing BG  to disk ... 
 - Saving arrays/scalars: bg_auto_F_bg, bg, bg_time_s, Ph_p, Lim, nperiods, bg_dd, bg_auto_th, bg_da, bg_auto_th_us0, bg_aa, bg_ad, 
 - Saving HDF5 attributes: bg_fun, bg_fun_name, 
 [DONE]

In [13]:
compare_data_bg(d1, d2)

In [14]:
d2.calc_bg_cache(bg.exp_fit, time_s=20, tail_min_us='auto', F_bg=1.7)


 * Loading BG rates from cache ... 
 - Loading arrays/scalars: Lim, Ph_p, bg, bg_aa, bg_ad, bg_auto_F_bg, bg_auto_th, bg_auto_th_us0, bg_da, bg_dd, bg_time_s, nperiods, 
 - Loading HDF5 attributes: bg_fun, bg_fun_name, signature, 
 - Generating additional fields: bg, bg_dd, bg_ad, bg_da, bg_aa, 
 [DONE]

In [15]:
compare_data_bg(d1, d2)

Direct test of bg_cache function


In [16]:
bg_cache.remove_cache(d2)


 * Removing all the cached background data ... [DONE]

In [17]:
d1.calc_bg(bg.exp_fit, time_s=20, tail_min_us=300)
bg_cache.calc_bg_cache(d2, fun=bg.exp_fit, time_s=20, tail_min_us=300)


 - Calculating BG rates ... [DONE]
 * No cached BG rates, recomputing:
 - Calculating BG rates ... [DONE]
 * Storing BG  to disk ... 
 - Saving arrays/scalars: bg, bg_time_s, Ph_p, Lim, nperiods, bg_dd, bg_auto_th, bg_da, bg_th_us_user, bg_aa, bg_ad, 
 - Saving HDF5 attributes: bg_fun, bg_fun_name, 
 [DONE]

In [18]:
compare_data_bg(d1, d2)

In [19]:
bg_cache.calc_bg_cache(d2, fun=bg.exp_fit, time_s=20, tail_min_us=300)


 * Loading BG rates from cache ... 
 - Loading arrays/scalars: Lim, Ph_p, bg, bg_aa, bg_ad, bg_auto_th, bg_da, bg_dd, bg_th_us_user, bg_time_s, nperiods, 
 - Loading HDF5 attributes: bg_fun, bg_fun_name, signature, 
 - Generating additional fields: bg, bg_dd, bg_ad, bg_da, bg_aa, 
 [DONE]

In [20]:
compare_data_bg(d1, d2)

In [21]:
d1.calc_bg(bg.exp_fit, time_s=20, tail_min_us='auto', F_bg=1.7)
bg_cache.calc_bg_cache(d2, fun=bg.exp_fit, time_s=20, tail_min_us='auto', F_bg=1.7)


 - Calculating BG rates ... [DONE]
 * No cached BG rates, recomputing:
 - Calculating BG rates ... [DONE]
 * Storing BG  to disk ... 
 - Saving arrays/scalars: bg_auto_F_bg, bg, bg_time_s, Ph_p, Lim, nperiods, bg_dd, bg_auto_th, bg_da, bg_auto_th_us0, bg_aa, bg_ad, 
 - Saving HDF5 attributes: bg_fun, bg_fun_name, 
 [DONE]

In [22]:
compare_data_bg(d1, d2)

In [23]:
bg_cache.calc_bg_cache(d2, fun=bg.exp_fit, time_s=20, tail_min_us='auto', F_bg=1.7)


 * Loading BG rates from cache ... 
 - Loading arrays/scalars: Lim, Ph_p, bg, bg_aa, bg_ad, bg_auto_F_bg, bg_auto_th, bg_auto_th_us0, bg_da, bg_dd, bg_time_s, nperiods, 
 - Loading HDF5 attributes: bg_fun, bg_fun_name, signature, 
 - Generating additional fields: bg, bg_dd, bg_ad, bg_da, bg_aa, 
 [DONE]

In [24]:
compare_data_bg(d1, d2)

In [25]:
print 'OK'


OK

In [25]: